<?php

/**
 * CotizacionNacional form.
 *
 * @package    dirsac
 * @subpackage form
 * @author     Miguel Flores
 * @version    SVN: $Id: sfDoctrineFormTemplate.php 23810 2009-11-12 11:07:44Z Kris.Wallsmith $
 */
class CotizacionNacionalForm extends BaseCotizacionNacionalForm
{
  public function configure()
  {
	unset($this['created_at'], $this['updated_at']);
    $this->embedRelation('ItemCotizacionNacional');
    $this->widgetSchema['estado'] ->setAttribute('type', 'hidden');
    
    $this->validatorSchema['correo_encargado'] = new sfValidatorEmail();
    $this->validatorSchema['correo_encargado']->setMessage('invalid', 'Formato de correo incorrecto');
    $this->validatorSchema['correo_encargado']->setMessage('required', 'Campo es requerido');
    
    $this->widgetSchema['plazo_entrega'] = new sfWidgetFormInputText();
    $this->widgetSchema['plazo_entrega']->setAttribute('class', 'datepicker');
    
    //$this->widgetSchema['observacion']=new sfWidgetFormInputText();
  }

  public function addNewFields($number){
    //$new_occurrences = new BaseForm();
    $new_items = new BaseForm();

    for($i=0; $i <= $number; $i+=1){
      //$occurrence = new Occurrence();
      $item = new ItemCotizacionNacional();
      
      //$occurrence->setEvent($this->getObject());
      $item->setCotizacionNacional($this->getObject());
      
      //$occurrence_form = new OccurrenceForm($occurrence);
      $item_form = new ItemCotizacionNacionalForm($item);

      //$new_occurrences->embedForm($i,$occurrence_form);
      $new_items->embedForm($i,$item_form);
    }

    //$this->embedForm('new', $new_occurrences);
    $this->embedForm('new', $new_items);
  }

  public function bind(array $taintedValues = null, array $taintedFiles = null){

    //$new_occurrences = new BaseForm();
    $new_items = new BaseForm();
    
    //foreach($taintedValues['new'] as $key => $new_occurrence){
    foreach($taintedValues['new'] as $key => $new_item){
        
      //$occurrence = new Occurrence();
      $item = new ItemCotizacionNacional();
      
      //$occurrence->setEvent($this->getObject());
      $item->setCotizacionNacional($this->getObject());
      
      //$occurrence_form = new OccurrenceForm($occurrence);
      $item_form = new ItemCotizacionNacionalForm($item);

      //$new_occurrences->embedForm($key,$occurrence_form);
      $new_items->embedForm($key,$item_form);
    }

    //$this->embedForm('new',$new_occurrences);
    $this->embedForm('new',$new_items);

    parent::bind($taintedValues, $taintedFiles);
  }
}
